/**
 * 
 */
package ac.svn.accesscontrol.ui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.GridLayout;

import javax.swing.Icon;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.MatteBorder;

/**
 * @author Enigmanic
 *
 */
public class AccessUnitListCell extends JPanel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private JCheckBox readCheckBox;
	private JCheckBox writeCheckBox;
	private JLabel titleLabel;
	private static Font selectedFont;
	private static Font defFont;
	public AccessUnitListCell()
	{
		super(new BorderLayout(5,0),true);
		initComponents();
	}
	

	private void initComponents() 
	{
		setBorder(new MatteBorder(1,3,1,1,(new Color(104,204,255))));
		titleLabel = new JLabel();
		readCheckBox = new JCheckBox("Read", true);
		writeCheckBox= new JCheckBox("Write", false);
		
		JPanel  panel = new JPanel((new GridLayout(1, 2, 0, 3)),true);
		
		panel.add(readCheckBox);
		panel.add(writeCheckBox);
		
		add(titleLabel,BorderLayout.CENTER );
		add(panel,BorderLayout.EAST);
		
		if(null == selectedFont )
		{
			initFont();
		}
	}
	
	private void initFont() {
		defFont = titleLabel.getFont();
		selectedFont = new Font(defFont.getFamily(),Font.BOLD,defFont.getSize()+2);
	}


	public void setIcon(Icon icon )
	{
		titleLabel.setIcon(icon);
	}
	
	public void setTitle(String title)
	{
		titleLabel.setText(title);
	}
	
	public void setAccess(boolean r,boolean w)
	{
		readCheckBox.setSelected(r);
		writeCheckBox.setSelected(w);
	}
	
	public boolean getRead()
	{
		return readCheckBox.isSelected();
	}
	
	public boolean getWrite()
	{
		return writeCheckBox.isSelected();
	}
	
	public void setSelected(boolean b)
	{
		if(b)
		{
			setFont(selectedFont);
		}
		else
		{
			setFont(defFont);
		}
	}
	

}
